Shader "Unlit/VertexOffset"
{
    Properties
    {
        //_MainTex ("Texture", 2D) = "white" {}
        _ColorA ("Color A",Color) = (1,1,1,1)
        _ColorB ("Color B",Color) = (1,1,1,1)
        _ColorStart("Color Start",Range(0,1)) = 0
        _ColorEnd("Color End",Range(0,1)) = 1    
        _WaveAmp("Wave Amptitude",Range(0,0.2)) = 0.1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque"}
        LOD 100

        Pass
        {

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            float4 _ColorA;
            float4 _ColorB;
            float _Scale;
            float _ColorStart;
            float _ColorEnd;
            float _WaveAmp;
            
            sampler2D _MainTex;
            float4 _MainTex_ST;
            
            struct mesh_data
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                float3 normal : NORMAL;
            };

            struct Interolators
            {
                float4 vertex : SV_POSITION;
                float3 normal : TEXCOORD0;
                float2 uv : TEXCOORD1;
            };


            float GetWave(float2 uv)
            {
                const float2 uvsCentered = uv * 2 -1;
                const float radioDistance = length(uvsCentered);
                //return float4(radioDistance.xxx,1);
                float wave = cos( (radioDistance  - _Time.y * 0.1) * 6.18 * 5) * 0.5 + 0.5;
                wave *= 1 - radioDistance;
                return wave;
            }
            
            Interolators vert (mesh_data meshData)
            {
                Interolators o;
                meshData.vertex.y = GetWave(meshData.uv) * _WaveAmp;
                o.vertex = UnityObjectToClipPos(meshData.vertex);
                o.normal = UnityObjectToWorldNormal(meshData.normal);
                o.uv = meshData.uv;
                return o;
            }

            float InverseLerp(float a,float b, float v)
            {
                return (v-a)/ (b-a);
            }

                        
            fixed4 frag (Interolators i) : SV_Target
            {
                float radioDistance = length(i.uv * 2 -1);
                float wave = GetWave(i.uv);
                float4 gradient = lerp(_ColorA,_ColorB,radioDistance);
                return wave * gradient;
                // float xOffset = cos(i.uv.x * 6.18 * 8) * 0.01;
                // float topBottomRemover =  t * (abs(i.normal.y) < 0.999);
                // float waves = t * topBottomRemover;
                // return gradient * waves;

                //return float4(i.uv.xy,0,1);
                
                //float t = saturate(InverseLerp(_ColorStart,_ColorEnd,i.uv.x));
                //float4 outColor = lerp(_ColorA,_ColorB,t);
                //return outColor;
            }
            ENDCG
        }
    }
}
